#############################################################
#################      Survey Plot (2005)       #############
###############      October 10, 2018    ##################
##########   Rerun: December 16, 2022 


rm(list = ls())  
library(foreign)
library(readstata13)
library(ggplot2)  
library(scales)

data=read.dta13("~/Dropbox/Personal Research 2017/replications/IHDS_karn05.dta")
names(data)
table(data$DISTNAME)



#total 
kar=data[which(data$DISTNAME=="Shimoga"|data$DISTNAME=="Davanagere"|
                 data$DISTNAME=="Chitradurga"|data$DISTNAME=="Uttar Kannad"|
                 data$DISTNAME=="Haveri"|data$DISTNAME=="Gadag"|
                 data$DISTNAME=="Dharwad"|data$DISTNAME=="Koppal"|
                 data$DISTNAME=="Raichur"|
                 data$DISTNAME=="Gulbarga"|data$DISTNAME=="Bagalkot"|
                 data$DISTNAME=="Bijapur"),]

kar$tr=1
kar$tr[kar$DISTNAME=="Bagalkot"|
         kar$DISTNAME=="Haveri"|kar$DISTNAME=="Bijapur"|
         kar$DISTNAME=="Gadag"|kar$DISTNAME=="Uttar Kannad"|
         kar$DISTNAME=="Dharwad"]=0
table(kar$tr)

####confidence in politicians

#delete unnecessary categoies, like I do not know. 
table(kar$CI1)
kargov=kar[which(kar$CI1=="A great deal"|kar$CI1=="Only some"|
                   kar$CI1=="Hardly any"),]
table(kargov$CI1)

#change categories
kargov$ci1=1 #confident 
#kar$ci4[kar$CI4=="Only some confidence"|kar$CI4=="Hardly any confidence at all"]=0 #not confident 
kargov$ci1[kargov$CI6=="Hardly any"]=0 #not confident 

table(kargov$ci1, kargov$tr)

g1=ggplot(kargov, aes(x=factor(ci1), group=factor(tr)))+
  geom_bar(aes(y = ..prop.., fill = factor(tr)), stat="count", position=position_dodge())+
  xlab("Confidence in politicians")+ylab("Count")+
  scale_fill_grey(start=0.8, end=0.2, name="Treatment Group",
                  labels=c("Direct Rule", "Indirect Rule"))+
  labs(y = "Percent") +
  geom_text(aes( label = scales::percent(..prop..),
                 y= ..prop.. ), stat= "count", position = position_dodge(0.9), vjust=-0.33) +
  scale_y_continuous(labels=percent)

g1


pdf("surveyplot2005.pdf",width=7,height=5)
g1
dev.off()








